package com.stary.code.springboot.config;

import java.util.Map;

import com.stary.code.springboot.Constants;
import com.stary.code.springboot.rules.WebViewType;

/**
 * <p>Spring Boot项目配置类</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2018-6-29
 */
public class SpringBootProjectConfig {
	/**
	 * springboot版本，默认1.5.22
	 */
	private String springBootVersion = "1.5.22";
	/**
	 * java版本，默认1.7
	 */
	private String javaVersion = "1.7";
	/**
	 * 是否开启视图，默认false
	 */
	private boolean openView = false;
	/**
	 * 是否开启数据源，默认false
	 */
	private boolean openDataSource = false;
	/**
	 * 是否开启自定义logback，默认true
	 */
	private boolean openLogback = true;
	/**
	 * web视图类型，默认 thymeleaf
	 */
	private WebViewType viewType = WebViewType.THYMELEAF;
	/**
	 * 需要的依赖
	 */
	private Map<String, String> dependencyMap;
	/**
	 * 是否生成表结构文档，默认false
	 */
	private boolean tableDocCreated = false;
	/**
	 * 是否开启热部署，默认true
	 */
	private boolean openDevTools = true;
	
	public String getSpringBootVersion() {
		if ( springBootVersion != null && !springBootVersion.contains(Constants.SPRINGBOOT_RELEASE)) {
			springBootVersion += Constants.SPRINGBOOT_RELEASE;
		}
		return springBootVersion;
	}
	public SpringBootProjectConfig setSpringBootVersion(String springBootVersion) {
		this.springBootVersion = springBootVersion;
		return this;
	}
	public String getJavaVersion() {
		if (Constants.SPRINGBOOT_1.equals(getSpringBootVersion().substring(0, 1))) {
			javaVersion = "1.7";
		}
		return javaVersion;
	}
	public SpringBootProjectConfig setJavaVersion(String javaVersion) {
		this.javaVersion = javaVersion;
		return this;
	}
	public boolean isOpenView() {
		return openView;
	}
	public SpringBootProjectConfig setOpenView(boolean openView) {
		this.openView = openView;
		return this;
	}
	
	public boolean isOpenDataSource() {
		if (!openDataSource) {
			tableDocCreated = false;
		}
		return openDataSource;
	}
	public SpringBootProjectConfig setOpenDataSource(boolean openDataSource) {
		this.openDataSource = openDataSource;
		return this;
	}
	
	public WebViewType getViewType() {
		return viewType;
	}
	public SpringBootProjectConfig setViewType(WebViewType viewType) {
		this.viewType = viewType;
		return this;
	}
	public Map<String, String> getDependencyMap() {
		return dependencyMap;
	}
	public SpringBootProjectConfig setDependencyMap(Map<String, String> dependencyMap) {
		this.dependencyMap = dependencyMap;
		return this;
	}
	public boolean isOpenLogback() {
		return openLogback;
	}
	public SpringBootProjectConfig setOpenLogback(boolean openLogback) {
		this.openLogback = openLogback;
		return this;
	}
	public boolean isTableDocCreated() {
		return tableDocCreated;
	}
	public SpringBootProjectConfig setTableDocCreated(boolean tableDocCreated) {
		this.tableDocCreated = tableDocCreated;
		return this;
	}
	public boolean isOpenDevTools() {
		return openDevTools;
	}
	public SpringBootProjectConfig setOpenDevTools(boolean openDevTools) {
		this.openDevTools = openDevTools;
		return this;
	}
		
}
